    /*------------------------------------------------------------------------
//                          Project CommonLib                           //
------------------------------------------------------------------------*/
#pragma once
 
#include <string>
#define MAX_STR_DEFAULT_SIZE 1024 //0xfff   

class  CmString 
{
public:
    CmString();
    CmString(const char *str);
    CmString(const char ch);
	CmString(const CmString &str);
	CmString(const std::string &str);
	
    ~CmString();


	size_t	GetLength() const;
	bool	IsEmpty() const;
	void	Clear();    
	char	GetAt(unsigned int idx) const;
	void	SetAt(unsigned int idx, char src);
	char*	c_str();

    bool Find(const CmString &str) const;
    bool Find(const char *str) const;

    void Replace(const char *src, const char *dst);
    const char* Format(const char* format, ...);    

    operator char*() const;

    bool operator==(const CmString &str) const;
    bool operator==(const char *str) const;

	CmString& operator=(const CmString &str);	
	bool operator<(const CmString &rh) const;

    friend CmString operator+(const char *src1, const CmString& src2);
    friend CmString operator+(char src1, const CmString& src2);
    friend CmString operator+(const CmString &src1, const char *src2);
    friend CmString operator+(const CmString &src1, char src2);
    friend CmString operator+(const CmString &src1, const CmString &src2);

    //protected:
    int Compare(const char *str) const;
    static CmString Concat(const CmString &str1, const CmString &str2);
    void SetLength(const size_t& size) const;




	//std::string
	bool	empty() const;
	size_t  size()	const;	
	int compare(const char *str) const;

private:
	mutable size_t m_length;
	char m_defaultBuf[MAX_STR_DEFAULT_SIZE];
	char *m_buf;

	operator unsigned int() const;

};

//////////////////////////////////////////////////////////////////////////
// CmWString
//////////////////////////////////////////////////////////////////////////
class  CmWString
{
public:
    CmWString();
    CmWString(const TCHAR *str);
    CmWString(const TCHAR ch);
    CmWString(const CmWString &str);
	CmWString(const std::wstring &str);
    ~CmWString();
	
	size_t GetLength() const;
    bool IsEmpty() const;
    void Clear();    
    TCHAR GetAt(unsigned int idx) const;
    void SetAt(unsigned int idx, TCHAR src);

	TCHAR* c_str();
	const TCHAR* c_str() const;
	bool Find(const CmWString &str) const;
    bool Find(const TCHAR *str) const;

    void Replace(const TCHAR *src, const TCHAR *dst);
    const TCHAR * Format(const TCHAR* format, ...);    

    operator TCHAR *() const;
    

    friend bool operator==(const CmWString &lhr, const CmWString &rhr);
    bool operator==(const TCHAR *str) const;

    CmWString& operator=(const CmWString &str);
	bool operator<(const CmWString &rh) const;
    bool operator!=(const CmWString &rh) const;
    

    friend CmWString operator+(const TCHAR *src1, const CmWString& src2);
    friend CmWString operator+(TCHAR src1, const CmWString& src2);
    friend CmWString operator+(const CmWString &src1, const TCHAR *src2);
    friend CmWString operator+(const CmWString &src1, TCHAR src2);
    friend CmWString operator+(const CmWString &src1, const CmWString &src2);

protected:
    int Compare(const TCHAR *str) const;
    static CmWString Concat(const CmWString &str1, const CmWString &str2);
	void SetLength(const size_t& size) const;

    mutable size_t m_length;
    TCHAR m_defaultBuf[MAX_STR_DEFAULT_SIZE];
    TCHAR *m_buf;

	//std::wstring
	bool		empty() const;
	size_t  	size()	const;
	int compare(const TCHAR *wstr) const;

private:
	operator unsigned int() const;
};
